package laba1.task2;

import static java.lang.Math.pow;
import static java.lang.Math.sqrt;

/**
 *
 * @author yakimovich
 */
public class Point {

    private int x;
    private int y;

    /**
     * creates a Point by default
     */
    public Point() {
    }

    /**
     * created a Point by the specified coordinates
     */
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    /**
     *
     * @return the X coordinate of the point
     */
    public int getX() {
        return x;
    }

    /**
     *
     * @param x the x coordinate of the new location
     */
    public void setX(int x) {
        this.x = x;
    }

    /**
     *
     * @return the Y coordinate of the point
     */
    public int getY() {
        return y;
    }

    /**
     *
     * @param y the y coordinate of the new location
     */
    public void setY(int y) {
        this.y = y;
    }

    /**
     * move this Point at location (x + dx, y + dy)
     *
     * @param dx the distance to move this point along the x axis
     * @param dy the distance to move this point along the x axis
     */
    public void shift(int dx, int dy) {
        setX(getX() + dx);
        setY(getY() + dy);
    }

    /**
     * move this Point at location (x * factor, y * factor)
     *
     * @param factor
     */
    public void translate(int factor) {
        setX(getX() * factor);
        setY(getY() * factor);
    }

    /**
     * determines the distance between this Point and the specified Point
     *
     * @param p the specified Point
     * @return the distance between this Point and the specified Point
     */
    public double distanceTo(Point p) {
        double result = 0;
        if (p != null) {
            result = pow(p.x - this.x, 2) + pow(p.y - this.y, 2);
            result = sqrt(result);
        }
        return result;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 19 * hash + this.x;
        hash = 19 * hash + this.y;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Point other = (Point) obj;
        if (this.x != other.x) {
            return false;
        }
        if (this.y != other.y) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "(" + x + "; " + y + ")";
    }
}
